# -*- coding: utf-8 -*-
"""
Created on Sun Mar 26 13:06:55 2023

@author: lenovo
"""
#%%------------------------------------------------------------------------
import tkinter as tk
from calculate import Calculator
class CalculatorGUI:
    
    def __init__(self, master):
        self.master = master
        master.title("Calculator")
        
        self.num1_label = tk.Label(master, text="First number:")
        self.num1_label.grid(row=0, column=0)
        self.num1_entry = tk.Entry(master)
        self.num1_entry.grid(row=0, column=1)
        
        self.num2_label = tk.Label(master, text="Second number:")
        self.num2_label.grid(row=1, column=0)
        self.num2_entry = tk.Entry(master)
        self.num2_entry.grid(row=1, column=1)
        
        self.operation_label = tk.Label(master, text="Operation:")
        self.operation_label.grid(row=2, column=0)
        self.operation_entry = tk.Entry(master)
        self.operation_entry.grid(row=2, column=1)
        
        self.result_label = tk.Label(master, text="Result:")
        self.result_label.grid(row=3, column=0)
        self.result_entry = tk.Entry(master, state="readonly")
        self.result_entry.grid(row=3, column=1)
        
        self.calculate_button = tk.Button(master, text="Calculate", command=self.calculate)
        self.calculate_button.grid(row=4, column=0, columnspan=2)
        
        self.quit_button = tk.Button(master, text="Quit", command=master.quit)
        self.quit_button.grid(row=5, column=0, columnspan=2)
    
    def calculate(self):
        num1 = float(self.num1_entry.get())
        num2 = float(self.num2_entry.get())
        operation = self.operation_entry.get()
        calculator = Calculator()
        if operation == "+":
            result = calculator.add(num1, num2)
        elif operation == "-":
            result = calculator.subtract(num1, num2)
        elif operation == "*":
            result = calculator.multiply(num1, num2)
        elif operation == "/":
            result = calculator.divide(num1, num2)
        else:
            result = "Error: invalid operation"
        self.result_entry.config(state="normal")
        self.result_entry.delete(0, tk.END)
        self.result_entry.insert(0, result)
        self.result_entry.config(state="readonly")
if __name__ == "__main__":
    root = tk.Tk()
    calculator_gui = CalculatorGUI(root)
    root.mainloop()
    
#%%-----------------------------------------------------------------
import tkinter as tk
#from calculator import Calculator
from calculate import Calculator
class CalculatorGUI:
    
    def __init__(self, master):
        self.master = master
        master.title("Calculator")
        
        self.num1_label = tk.Label(master, text="First number:")
        self.num1_label.grid(row=0, column=0)
        self.num1_entry = tk.Entry(master)
        self.num1_entry.grid(row=0, column=1)
        
        self.num2_label = tk.Label(master, text="Second number:")
        self.num2_label.grid(row=1, column=0)
        self.num2_entry = tk.Entry(master)
        self.num2_entry.grid(row=1, column=1)
        
        self.operation_label = tk.Label(master, text="Operation:")
        self.operation_label.grid(row=2, column=0)
        self.operation_entry = tk.Entry(master)
        self.operation_entry.grid(row=2, column=1)
        
        self.result_label = tk.Label(master, text="Result:")
        self.result_label.grid(row=3, column=0)
        self.result_entry = tk.Entry(master, state="readonly")
        self.result_entry.grid(row=3, column=1)
        
        self.calculate_button = tk.Button(master, text="Calculate", command=self.calculate)
        self.calculate_button.grid(row=4, column=0, columnspan=2)
        
        self.clear_button = tk.Button(master, text="Clear", command=self.clear)
        self.clear_button.grid(row=5, column=0, columnspan=2)
        
        self.quit_button = tk.Button(master, text="Quit", command=master.quit)
        self.quit_button.grid(row=6, column=0, columnspan=2)
        
        self.history_label = tk.Label(master, text="History:")
        self.history_label.grid(row=0, column=2)
        self.history_listbox = tk.Listbox(master)
        self.history_listbox.grid(row=1, column=2, rowspan=6)
    
    def calculate(self):
        num1 = float(self.num1_entry.get())
        num2 = float(self.num2_entry.get())
        operation = self.operation_entry.get()
        calculator = Calculator()
        if operation == "+":
            result = calculator.add(num1, num2)
        elif operation == "-":
            result = calculator.subtract(num1, num2)
        elif operation == "*":
            result = calculator.multiply(num1, num2)
        elif operation == "/":
            result = calculator.divide(num1, num2)
        else:
            result = "Error: invalid operation"
        self.result_entry.config(state="normal")
        self.result_entry.delete(0, tk.END)
        self.result_entry.insert(0, result)
        self.result_entry.config(state="readonly")
        self.history_listbox.insert(tk.END, f"{num1} {operation} {num2} = {result}")
    
    def clear(self):
        self.num1_entry.delete(0, tk.END)
        self.num2_entry.delete(0, tk.END)
        self.operation_entry.delete(0, tk.END)
        self.result_entry.config(state="normal")
        self.result_entry.delete(0, tk.END)
        self.result_entry.config(state="readonly")
        self.history_listbox.delete(0, tk.END)
if __name__ == "__main__":
    root = tk.Tk()
    calculator_gui = CalculatorGUI(root)
    root.mainloop()
    
#%%---------------------------------------------------------------------------------------------
import tkinter as tk
from tkinter import ttk
#from calculator import Calculator
from calculate import Calculator
class CalculatorGUI:
    
    def __init__(self, master):
        self.master = master
        master.title("Calculator")
        master.geometry("400x400")
        
        self.background_image = tk.PhotoImage(file="background.png")
        self.background_label = tk.Label(master, image=self.background_image)
        self.background_label.place(x=0, y=0, relwidth=1, relheight=1)
        
        self.style = ttk.Style()
        self.style.configure("TButton", font=("Helvetica", 16), padding=10)
        
        self.num1_label = tk.Label(master, text="First number:", font=("Helvetica", 16))
        self.num1_label.place(x=50, y=50)
        self.num1_entry = tk.Entry(master, font=("Helvetica", 16))
        self.num1_entry.place(x=200, y=50)
        
        self.num2_label = tk.Label(master, text="Second number:", font=("Helvetica", 16))
        self.num2_label.place(x=50, y=100)
        self.num2_entry = tk.Entry(master, font=("Helvetica", 16))
        self.num2_entry.place(x=200, y=100)
        
        self.operation_label = tk.Label(master, text="Operation:", font=("Helvetica", 16))
        self.operation_label.place(x=50, y=150)
        self.operation_entry = tk.Entry(master, font=("Helvetica", 16))
        self.operation_entry.place(x=200, y=150)
        
        self.exponent_checkbutton_var = tk.BooleanVar()
        self.exponent_checkbutton = tk.Checkbutton(master, text="Exponent", variable=self.exponent_checkbutton_var, font=("Helvetica", 16))
        self.exponent_checkbutton.place(x=200, y=200)
        
        self.result_label = tk.Label(master, text="Result:", font=("Helvetica", 16))
        self.result_label.place(x=50, y=250)
        self.result_entry = tk.Entry(master, state="readonly", font=("Helvetica", 16))
        self.result_entry.place(x=200, y=250)
        
        self.calculate_button = ttk.Button(master, text="Calculate", command=self.calculate)
        self.calculate_button.place(x=50, y=300)
        
        self.clear_button = ttk.Button(master, text="Clear", command=self.clear)
        self.clear_button.place(x=175, y=300)
        
        self.quit_button = ttk.Button(master, text="Quit", command=master.quit)
        self.quit_button.place(x=300, y=300)
        
        self.history_label = tk.Label(master, text="History:", font=("Helvetica", 16))
        self.history_label.place(x=250, y=50)
        self.history_listbox = tk.Listbox(master, font=("Helvetica", 16))
        self.history_listbox.place(x=250, y=100, width=150, height=200)
    
    def calculate(self):
        num1 = float(self.num1_entry.get())
        num2 = float(self.num2_entry.get())
        operation = self.operation_entry.get()
        calculator = Calculator()
        if self.exponent_checkbutton_var.get():
            result = calculator.exponent(num1, num2)
        elif operation == "+":
            result = calculator.add(num1, num2)
        elif operation == "-":
            result = calculator.subtract(num1, num2)
        elif operation == "*":
            result = calculator.multiply(num1, num2)
        elif operation == "/":
            result = calculator.divide(num1, num2)
        else:
            result = "Error: invalid operation"
        self.result_entry.config(state="normal")
        self.result_entry.delete(0, tk.END)
        self.result_entry.insert(0, result)
        self.result_entry.config(state="readonly")
        self.history_listbox.insert(tk.END, f"{num1} {operation} {num2} = {result}")
    
    def clear(self):
        self.num1_entry.delete(0, tk.END)
        self.num2_entry.delete(0, tk.END)
        self.operation_entry.delete(0, tk.END)
        self.result_entry.config(state="normal")
        self.result_entry.delete(0, tk.END)
        self.result_entry.config(state="readonly")
        self.history_listbox.delete(0, tk.END)
if __name__ == "__main__":
    root = tk.Tk()
    calculator_gui = CalculatorGUI(root)
    root.mainloop()